package gather;

import java.util.ArrayList;

//定义集合添加学生对象，遍历，学生属性姓名年龄
public class G4 {
    public static void main(String[] args) {
        //1.创建集合
        ArrayList<Student> list = new ArrayList<>();
        //2.创建学生对象
        Student s1=new Student("zhangsan",18);
        Student s2=new Student("wangwu",19);
        Student s3=new Student("lisi",20);
        //3.添加元素
        list.add(s1);
        list.add(s2);
        list.add(s3);
        //4.遍历集合
        for (int i = 0; i < list.size(); i++) {
            Student stu=list.get(i);
            System.out.println(stu.getName()+", "+stu.getAge());
        }
    }
}
